/*
 * @Description: 将tokens数组转为dom字符串
 * @Author: wangqi
 * @Date: 2021-05-06 23:00:02
 * @LastEditTime: 2021-05-08 10:26:58
 */
import lookup from './lookup';
import parseArray from './parseArray';

function renderTemplate(tokens, data) {
    // 结果字符串
    let resultStr = '';
    for (let i = 0; i < tokens.length; i++) {
        let token = tokens[i];
        if (token[0] == 'text') {
            resultStr += token[1];
        } else if (token[0] == 'name') {
            resultStr += lookup(data, token[1]);
        } else if (token[0] == '#') {
            resultStr += parseArray(token, data);
        }
    }
    return resultStr;
};

export default renderTemplate
